home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-03-06 | 1.5 KB | 58 lines | [TEXT/GEOL] |
- Item 6393689 11-Feb-91 09:08PST
-
- From: CHANDLER1 Chandler, Dick
-
- To: MACAPP.TECH$ MacApp Technical
-
- ------------------------------------------------------------------------------
-
- Sub: overloading '=' operator
-
- I'm having trouble with overloading the '=' operator.
-
- I think my overload is written correctly, but its never being called.
-
- I declare to 'bars' which are music objects with:
-
- The C++ compiler is coping the address of bar1 into bar2
-
- TBar *bar1, *bar2;
-
- Then I instantiate them with the following call:
-
-
- bar1 = new TBar();
- bar2 = new TBar();
-
- After filling bar1 with note objects I call:
-
- bar2 = bar1;
-
- Before this call both objects have different pointers, after the call they both
- have the pointer that bar1 had oringinally. So it seems the compiler is simply
- coping the pointer. The overloaded '=' operator is never called.
-
- I want to keep them as pointers and create them on the fly, any suggestions or
- observations on something wrong!?!?
-
- Thanks - Dick
-
- enclosed is the operator function which isn't being called.
- /*************************************************************************
- * NAME: + overload for TBar
- *
- * FUNCTION: TBar = TBar
- **************************************************************************/
- TBar& TBar::operator = (TBar& sourceBar)
- {
-
- short loop = 0;
- while( sourceBar.fNotes[loop] && loop<kMaxNotes )
- {
- this->fNotes[loop] = sourceBar.fNotes[loop];
- }
- return *this;
-
- }
-
-